"""
@name : 局域存活IP检测
@author : shiyaling
@projectname : xsfh
"""
import subprocess
from IPy import IP
try:
    ip = IP(input("请输入要检查的网段："))
    ip.version()
    fp1 = open("used_ip.txt","a+")
    fp2 = open("unused_ip.txt","a+")
    for i in ip:
        cmd = 'ping -c 3 -w 1 i'
        p = subprocess.run(cmd,
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=True)
        if p.returncode == 0:
            print(f"{i}已被使用")
            fp1.write(f"{i}\n")
        else:
            print(f"{i}没被使用")
            fp2.write(f"{i}\n")
except:
    print("输入错误！")





